//
//  RecommendViewController.swift
//  斗鱼直播Swift
//
//  Created by admin on 2018/2/28.
//  Copyright © 2018年 admin. All rights reserved.
//

import UIKit
private let kItemMargin : CGFloat = 10 //间距
private let kItemW = (kScreenW - 3 * kItemMargin) / 2 //宽度
private let kItemH = kItemW * 3 / 4 //cell高度
private let kHeaderViewH : CGFloat = 50 //高度

class RecommendViewController: UIViewController {
    private lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSize.init(width: kItemW, height: kItemH)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = kItemMargin
        layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10)
        layout.headerReferenceSize = CGSize.init(width: kScreenW, height: kHeaderViewH)
        let coll = UICollectionView.init(frame:view.bounds, collectionViewLayout: layout)
        coll.dataSource = self
        coll.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "\(UICollectionViewCell.self)")
        coll.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "123")
        return coll
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        
            setupUI()
    }

}

extension RecommendViewController {
    private func setupUI () {
        view.backgroundColor = UIColor.yellow
        view.addSubview(collectionView)
    }
    
}

extension RecommendViewController:UICollectionViewDataSource {
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 12
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if section == 0 {
            return 8
        }
        
        return 4

    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let  cell  = collectionView.dequeueReusableCell(withReuseIdentifier: "\(UICollectionViewCell.self)", for: indexPath)
        
        return cell
        
    }
    
    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "123", for: indexPath)
        
        return headerView
        
    }
}
